package constants

import (
	"JVM/Jvmgo/GoToJVM/instructions/base"
	"JVM/Jvmgo/GoToJVM/runtimeData"
)

/*
	包含了两个字节码指令：
	1. bipush	表示将单字节的常量值推送至栈顶 byte
	2. sipush	表示将短整型的常量值推送至栈顶 short
*/

type BIPUSH struct {
	val int8
}
type SIPUSH struct {
	val int16
}

func (self *BIPUSH) FetchOperands(reader *base.BytecodeReader) {
	self.val = reader.ReadInt8()
}

func (self *BIPUSH) Execute(frame *runtimeData.Frame) {
	i := int32(self.val)
	frame.OperandStack().PushInt(i)
}

func (self *SIPUSH) FetchOperands(reader *base.BytecodeReader) {
	self.val = reader.ReadInt16()
}

func (self *SIPUSH) Execute(frame *runtimeData.Frame) {
	i := int32(self.val)
	frame.OperandStack().PushInt(i)
}
